{% extends "master.html" %}
{% block subtitle %} - 店铺管理 - 更新店铺{% endblock %}

{% block extCSS %}
<style type="text/css">
    .atmtemplate{
        display : none;
    }
</style>
{% endblock %}


{% block extJS %}
<script language="JavaScript" type="text/javascript">
//<![CDATA[
    var extAtm = [];
    {% for a in obj.attachment %}
        extAtm.push({{a.id}});
    {% endfor %}

    $(document).ready(function(){
        $("#provinceID").change(function(){
            provinceChange(this,'#cityID');
        });
    });
    
    function toSubmit(){
        var msg = [];
        clearMsg();
        $(".err").removeClass('err');
        
        if(!$("#shortName").val()){
            msg.push('请填写商店的简称！');
            $("#shortName").addClass('err');
        }
        
        if(!$("#name").val()){
            msg.push('请填写商店的全称！');
            $("#name").addClass('err');
        }

                
        if(msg.length > 0){
            alertError(msg);
            return false;
        }else{
            $("form").submit();
        }
        
    }
    
    function toCancel(){
         redirect_alert("{{MSG_LEAVE_WITHOUT_SAVING}}","{{url_for('.view',action='view',id=obj.id)}}");
    }
//]]>
 </script>
{% endblock %}

{% block main %}
<div class="container">
    <div class="row">
        <ol class="breadcrumb">
          <li><a href="{{url_for('bpMas.view')}}">基础信息</a></li>
          <li><a href="{{url_for('bpShop.view')}}">店铺管理</a></li>
          <li class="active">更新店铺</li>
        </ol>
    </div>
    <div class="row">
        <div class="btn-toolbar pull-right">
            <div class="btn-group"><button type="button" class="btn btn-primary" onclick="toSubmit()">{{BTN_SUBMIT}}</button></div>
            <div class="btn-group"><button type="button" class="btn btn-inverse" onclick="toCancel()">{{BTN_CANCEL}}</button></div>
        </div>
    </div>
    <div class="row">
        <form class="" method='POST' action="{{url_for('bpShop.view',action='update')}}" enctype="multipart/form-data">
            <input type="hidden" name="id" value="{{obj.id}}"/>
            <input type="hidden" name="attachment" id="attachment" value="{{obj.attachment|join('|',attribute='id')}}"/>
            <fieldset>
                <legend>店铺基本信息</legend>
                <div class="col-md-4">
                    <div class="control-group">
                        <label class="control-label"><label for="no">系统编号</label></label>
                        <div class="controls"><input type="text" name="no" id="no" value="{{obj.no|f}}" readonly="true"/></div>
                    </div>
                    <div class="control-group">
                        <label class="control-label"><label for="shortName">店铺简称<span style='color:red'>*</span></label></label>
                        <div class="controls"><input type="text" name="shortName" id="shortName" value="{{obj.shortName|f}}"/></div>
                    </div>
                    <div class="control-group">
                        <label class="control-label"><label for="name">店铺全称<span style='color:red'>*</span></label></label>
                        <div class="controls"><input type="text" name="name" id="name" value="{{obj.name|f}}"/></div>
                    </div>
                    <div class="control-group">
                        <label class="control-label"><label for="address">地址</label></label>
                        <div class="controls">
                            {{mymacros.select('provinceID',list=getMaster('Province'),value=obj.provinceID)}}
                            {{mymacros.select('cityID',list=getCity(obj.provinceID),value=obj.cityID,blank_option=False)}}
                            <input name="address" id="address" value="{{obj.address|f}}"/>
                        </div>
                    </div>
                </div>
                <div class="col-md-4">
                    <div class="control-group">
                        <label class="control-label"><label for="fund">成立资金</label></label>
                        <div class="controls"><input type="text" name="fund" id="fund" value="{{obj.fund|f}}"/></div>
                    </div>
                    <div class="control-group">
                        <label class="control-label"><label for="name">法人代表</label></label>
                        <div class="controls"><input type="text" name="legalPerson" id="legalPerson" value="{{obj.legalPerson|f}}"/></div>
                    </div>      
                </div>     
                <div class="col-md-4">
                    <div class="control-group">
                        <label class="control-label"><label for="shopType">店铺类型</label></label>
                        <div class="controls">
                            <select name="shopType" id="shopType">
                                {% for v,n in [((SHOP_TYPE_MAIN|string),'总店'),((SHOP_TYPE_BRANCH|string),'门店')] %}
                                    {% if spobj.shopType == v %}
                                        <option value="{{v}}" selected="selected">{{n}}</option>
                                    {% else %}
                                        <option value="{{v}}">{{n}}</option>
                                    {% endif %}
                                {% endfor %}
                            </select>
                        </div>
                    </div>
                    <div class="control-group">
                        <label class="control-label"><label for="saleType">销售方式</label></label>
                        <div class="controls">
                            <select name="saleType" id="saleType">
                                {% for v,n in [(SHOP_SALE_TYPE_SELF|string,'自营'),(SHOP_SALE_TYPE_JOIN|string,'加盟')] %}
                                    {% if spobj.saleType == v %}
                                        <option value="{{v}}" selected="selected">{{n}}</option>
                                    {% else %}
                                        <option value="{{v}}">{{n}}</option>
                                    {% endif %}
                                {% endfor %}
                            </select>
                        </div>
                    </div>
                    <div class="control-group">
                        <label class="control-label"><label for="remark">备注</label></label>
                        <div class="controls"><textarea name="remark" id="remark">{{obj.remark|f}}</textarea></div>
                    </div>
                </div>
            </fieldset>
            <fieldset>
                <legend>店铺功能信息</legend>
                <div class="control-group">
                    <label class="control-label"><label for="">包含模块</label></label>
                    <div class="controls">
                        {{render_cb('销售产品模块','canSale',0,spobj.canSale)}}
                        {{render_cb('采购产品模块','canPurchase',0,spobj.canPurchase)}}
                        {{render_cb('仓存模块','canGetWarehouse',0,spobj.canGetWarehouse)}}
                        {{render_cb('更新商品模块','canUpdateProduct',0,spobj.canUpdateProduct)}}
                        {{render_cb('更新人员模块','canUpdateOfficer',0,spobj.canUpdateOfficer)}}
                    </div>
                </div>
            </fieldset>
            <fieldset>
                <legend>附件</legend>
                <div class="control-group">
                  <label class="control-label" for="attachment">附件</label>
                  <div class="controls">
                      {{mymacros.render_edit_all_attachment(obj.attachment)}}
                      <ul id="atmul" class="list-unstyled">
                          <li><input type="file" name="atm_10"/><a href="#" onclick="addAtm('atmtemplate','atmmk','#atmul')"><i class="glyphicon glyphicon-plus"></i></a></li>
                          <li class="atmtemplate"><input type="file" name="atm_x"/><a href="#" onclick="delAtm(this,'atmmk')"><i class="glyphicon glyphicon-minus"></i></a></li>
                      </ul>
                  </div>
                </div> 
            </fieldset>    
        </form>
    </div>
    
   
</div>
{% endblock %}



{% macro render_cb(label,name,v,cv) %}
     <label class="checkbox">
      {% if v == cv %}
        <input type="checkbox" name="{{name}}" value="{{v}}" checked="checked">
      {% else %}
        <input type="checkbox" name="{{name}}" value="{{v}}">
      {% endif %}
      {{label}}
    </label>
{% endmacro %}